import { resolve } from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import svgLoader from 'vite-svg-loader';
import configArcoStyleImportPlugin from './plugin/arcoStyleImport';
import AutoImport from 'unplugin-auto-import/vite';
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';

export default defineConfig({
  base: './',
  plugins: [
    vue(),
    vueJsx(),
    viteCommonjs(),
    svgLoader({ svgoConfig: {} }),
    configArcoStyleImportPlugin(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'src/auto-imports.d.ts',
      eslintrc: {
        enabled: true,
      },
    }),
  ],
  server: {
    // port: 8080, //端口号
    proxy: {
      '/api': {
        // target: 'http://192.168.110.115:8083/',
        target: 'http://www.dothing.com:6888/',
        changeOrigin: true, // 关键：开启跨域代理（模拟后端同源）
        rewrite: (path) => path.replace(/^\/api/, ''), // 移除请求路径中的 /api 前缀（根据后端接口调整）
      },
    },
  },
  resolve: {
    alias: [
      { find: '@', replacement: resolve(__dirname, '../src') },
      { find: 'assets', replacement: resolve(__dirname, '../src/assets') },
      { find: 'vue-i18n', replacement: 'vue-i18n/dist/vue-i18n.cjs.js' },
      { find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' },
    ],
    extensions: ['.ts', '.js'],
  },
  define: {
    'process.env': {},
    '__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': false,
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${resolve(
            'src/assets/style/breakpoint.less'
          )}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, '../index.html'),
      },
      output: {
        manualChunks: undefined, // 禁用代码分割
      },
    },
  },
});
